// my.js
var util = require('../../utils/util.js')
const date = new Date()
const months = []
const days = []
const hours = []
const mins = ['0','10','20','30','40','50']
 let str =  util.formatTime(date)
 console.log("////////")
 console.log(str, date.getFullYear(), new Date(2017, date.getMonth() + 1, 0).getDate())
for (let i = date.getMonth() +1 ; i < date.getMonth() + 3; i++) {
  months.push(i)
 
}
for (let i = date.getDate(); i < new Date(date.getFullYear(), date.getMonth() +1, 0).getDate() +1;i++){


  days.push(i)
}
for (let i = date.getHours(); i < 25; i++){

  hours.push(i)

}
// 



Page({

  /**
   * 页面的初始数据
   */
  data: {
  array:['1','2','3','4'],
  areas: [{ "id": 1, "name": "30分钟", "isSelect": false }, { "id": 2, "name": "60分钟", "isSelect": true }, { "id": 3, "name": "90分钟", "isSelect": false }, { "id": 4, "name": "120分钟", "isSelect": false }],
  years: months,
  month:date.getMonth() +1,
  days: days,
  hours: hours,
  mins:mins,
  currentYear: date.getFullYear(),
  index: 0,
  chooseDataArr:['aaa'],
  heade_image:"",
  screenHeight:555,
  screenHeigh11t: 200,
//预定时长 height
  choose_duration:0,
  amount_height:0,
  submit_height:0,
  //预定数量
  amount_total:0,
  //价钱
  price:0,
  location:"http://10.21.48.141"

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;


    wx.getSystemInfo({
      success: function (res) {
        console.log(res.model)
        console.log(res.pixelRatio)
        console.log(res.windowWidth)
        console.log(res.windowHeight)
        console.log(res.language)
        console.log(res.version)
        console.log(res.platform)

    that.setData({

      screenHeight: res.windowHeight,

      choose_duration: res.windowWidth * 0.24,
      amount_height: res.windowWidth * 0.13,
      submit_height: res.windowWidth * 0.31,
    })

      }
    }),



    wx.request({
      url: 'http://10.21.48.141/Untitled_copy1',
      success: function (res) {  
        console.log(res.data)
        let array = res.data.arraynumber
        let imageurl = that.data.location + res.data.head_image

        console.log(imageurl)
        for (let i = 0; i < array.length;i++ ){
          let url = array[i].iconImage
          array[i].iconImage = that.data.location + url

        }

        that.setData({

          chooseDataArr: array,
          heade_image: imageurl,
        })
        
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  console.log('hahahahaah')
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },

 /**
   * 当前选择
   */
  bindchanged: function (e){
  console.log('ddd')
  this.setDate({

    index : e.detail.value
  })
  },
 /**
   * 日期选择
   */
  bindChangeaa:function(e){
    const val = e.detail.value
  
    this.dangran(val)
  },
  
/**
   * 选择过程的日期 时间 处理
   */
  dangran: function (value){

    console.log(value)

    var newdays = []
    var newHours = []
 //月份的index   
    let monthindex = value[0]
//day的index
    let dayindex = value[1]
 // 选择月份 对应的处理
    if (monthindex >0){
 
      let daysCount = new Date(date.getFullYear(), date.getMonth() + 1 + monthindex, 0).getDate() 
 
  for (let i = 1; i < daysCount +1;i++){
       newdays.push(i)

  }
  
  for (let i = 1; i < 25; i++) {

    newHours.push(i)

  }


  }else{


  const date = new Date()
  for (let i = date.getDate(); i < new Date(date.getFullYear(),      date.getMonth() + 1, 0).getDate() + 1; i++) {


    newdays.push(i)
  }
  // 选择day 对应的处理
  if (dayindex > 0) {
    for (let i = 1; i < 25; i++) {

      newHours.push(i)

    }


  } else {

    newHours = hours


  }

}


this.setData({
  days: newdays,
  hours: newHours
})

  },
  /**
   * 预定时长
   */
  selectAreaOk: function (event) {
   
    var selectAreaId = event.currentTarget.dataset.areaid;
    var that = this
    console.log(selectAreaId)
    //areaId = selectAreaId
    var tempArray = that.data.areas
    for (let i = 0; i < tempArray.length;i++){

      tempArray[i].isSelect = false
    }
  

    tempArray[selectAreaId - 1].isSelect = true
    that.setData({

    
      areas: tempArray

    })
  
  },
/**
   * 选择跑步机点击
   */
  leftCellTap:function(e){

var that = this;
   
    var selectIndex = Number(e.currentTarget.dataset.idx);
    var choosenum = 0;
    var pricetotal = 0;
    console.log(selectIndex)
    var temArray = this.data.chooseDataArr;
    
    if (temArray[selectIndex -1].isselected){


    }else{

      
      if (temArray[selectIndex - 1].select){
      
        temArray[selectIndex - 1].select = false;       
       }else{
  
        temArray[selectIndex - 1].select = true; 
       }
     


    }
  for (var i = 0; i < temArray.length; i++){

        //temArray[i].select = false

        if (temArray[i].select){
          choosenum++;
        }
      }

    console.log(temArray[selectIndex - 1].select )
    pricetotal = choosenum * 20;
    that.setData({

      chooseDataArr: temArray,
      amount_total: choosenum,
      price: pricetotal
      })
  },
/**
   * 选择跑步机点击
   */
submit: function () {

   console.log('sssss')


  }
})
